
//
//  ListTestAlertView.m
//  xpkc
//
//  Created by 胡志飞 on 15/11/5.
//  Copyright © 2015年 TopSage. All rights reserved.
//

#import "LoginAlertView.h"
@interface LoginAlertView ()

@property (nonatomic, strong) UILabel *msgLabel;
@property (nonatomic, strong) UIImageView *imageVW;
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIView *backgroudView;
@end

@implementation LoginAlertView

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 5;
        [self initSubviews];
    }
    return self;

}

- (void)initSubviews {
    
    //提示框图片
    CGFloat imageVWY = 0;
    CGFloat imageVWH = 150;
    self.imageVW = [[UIImageView alloc]initWithFrame:CGRectMake(0.5*(self.frame.size.width-imageVWH), imageVWY, imageVWH, imageVWH)];
//    self.imageVW.backgroundColor = [UIColor redColor];
    self.imageVW.image = [UIImage imageNamed:@"loginAlert"];
    [self addSubview:self.imageVW];
    
    
    // 取消按钮
    CGFloat buttonW = 30;
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(CGRectGetWidth(self.frame)-buttonW, 0, buttonW, buttonW);
//    self.button.backgroundColor = [UIColor yellowColor];
    [self.button setBackgroundImage:[UIImage imageNamed:@"cancelbtn"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.button];
    
    
    // 提示框label
    CGFloat inset = -20; //imageView与label之间间距
    CGFloat msgLabelH = 30;
    self.msgLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.imageVW.frame)+inset, CGRectGetWidth(self.frame), msgLabelH)];
    self.msgLabel.textAlignment = NSTextAlignmentCenter;
    self.msgLabel.font = [UIFont systemFontOfSize:20];
//    self.msgLabel.backgroundColor = [UIColor greenColor];
    [self addSubview:self.msgLabel];


}

- (void)showWithMessage:(NSString *)msg {
    
    self.msgLabel.text = msg;
//    self.backgroudView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//    self.backgroudView.backgroundColor = [UIColor blackColor];
//    self.backgroudView.alpha = 0.5;
//    [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    

}
- (void)cancel {
    
    [self removeFromSuperview];
//    self.backgroudView.backgroundColor=[UIColor whiteColor];
//    self.backgroudView.alpha=1;
//    [self.backgroudView removeFromSuperview];
    
}

@end
